<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>this is 方案 1 </title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
    <!--以下三个是备用  浏览器打不开第一个 换下面的-->
    <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>-->
    <!--<script src="https://cdn.rawgit.com/zenorocha/clipboard.js/v2.0.0/dist/clipboard.min.js"></script>-->
    <!--<script src="https://unpkg.com/clipboard@2.0.0/dist/clipboard.min.js"></script>-->
</head>
<body>
<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git22" type="hidden" name="foo">
 
<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
  Copy to clipboard
</button>
 
<hr>
<br>
<!-- Trigger -->
<!-- <button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
    Copy to clipboard
</button> -->
 
<script>
    $(function($) {
        init();
    });
    function init(){
    //必须要初始化 第一种初始化
    var clipboard = new ClipboardJS('.btn',{
        text: function() {
            $("input:hidden[name='foo']").val("this is test text111");
            return $("input:hidden[name='foo']").val();
        }
    });
    clipboard.on('success', function(e) {
        console.log(e);
    });
    clipboard.on('error', function(e) {
        console.log(e);
    });
    }

 
 
</script>
</body>
</html>